//
// @Auther: by wujehy 
// @Email:wujehy@qq.com
// @Data:20-4-14
// @Time:下午1:56
//

#ifndef TESTSERVER_BASEBUSINESS_H
#define TESTSERVER_BASEBUSINESS_H

#include <iostream>
#include <handy/handy.h>

using namespace handy;

struct EventContext
{
    int mod_type;
    int sub_type;
    int taskid;
    TcpConnPtr con;
};

typedef int (*EventFunction)(EventContext *context, uint8_t *protoData, int datalen, void *userdata);

class BaseBusiness
{
//protected:
////    int currSubType;
////    int currMod;
////    int currTaskid;
////    std::map<int, EventFunction> eventMap;
public:
    static int call200(EventContext *context, std::string &body);

    static int call200(EventContext *context, void *data, int len);

    static int call200(int mod_type, int sub_type, int taskid, const TcpConnPtr &con, std::string &body);


    static int call401(EventContext *context);

    static int call500(EventContext *context, std::string errorMsgData);

    /**
     * @brief 事件分发
     * @param type_sub
     * @param taskid
     * @param con
     * @param protoData
     * @param datalen
     * @param userdata
     * @return
     */
    virtual int dispatchEvents(
            int type_sub, int taskid, const TcpConnPtr &con, uint8_t *protoData, int datalen,
            void *userdata = nullptr) = 0;

    /**
     * @brief 设置事件
     */
    virtual void setEvents() = 0;
};


#endif //TESTSERVER_BASEBUSINESS_H
